﻿@model VietPremier.Areas.AdminCP.Models.TravelCityModel
@{
    ViewBag.Title = "Tour du lichj";
    Layout = "~/Areas/AdminCP/Views/Shared/AdminLayout.cshtml";
}
@helper Truncate(string input, int length)
{
    if (input.Length <= length)
    { 
    @Html.Raw(input)
    }
    else
    { 
    @Html.Raw(input.Substring(0, length))<text>...</text>
    }
}

<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-ui-1.8.16.custom.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/custom/tables.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery.dataTables.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    jQuery(document).ready(function () {

    });

    $(".Hot").live("click", function () {
        var recordID = $(this).attr("data-id");
        $.post('/AdminCP/AdminTravelCity/SetStatus', { "id": recordID }, function (data) { alert("Change successfully") });
    });

    function DeleteRecord(id_TravelCity, id_TravelProduct) {
        var answer = confirm("Are you sure to delete this record?");
        if (answer) {
            var getURL = '@Url.Action("Delete", "AdminTravelCity")';
            $.get(getURL, { "id": id_TravelCity }, function (data) {
                if (data == "Ok") {
                    $('#nofError').hide();
                    $('#nofSuccess').show();
                    $('#msgNofSuccess').text("Delete Record Ok");
                    var strTemp = '@Url.Action("Index", "AdminTravelCity", new { idTravelProduct = "id_TravelProduct" })';
                    strTemp = strTemp.replace("id_TravelProduct", id_TravelProduct);
                    window.location.href = strTemp;
                }
                else {
                    $('#nofError').show();
                    $('#nofSuccess').hide();
                    $('#msgNofError').text("Cannot Delete Record");
                    alertMsg("Cannot delete, Please contact to website's technical");
                    //window.location.href = '@Url.Action("Index", "Error", new { errorMsg = "Can not delete!" })';
                }
            });
        }
        else {
            return false;
        }

        return false;
    }

</script>


<div class="maincontentinner">

    <ul class="maintabmenu">
        <li class="current"><a href="@Url.Action("Index", "AdminTravelProduct")">Quản lý sản phẩm du lịch</a></li>
        <li class="current"><a href="@Url.Action("Insert", "AdminTravelCity", new { idTravelProduct = @Model.travelProduct.Id })">Thêm tour du lịch mới</a></li>
    </ul>
    <!--maintabmenu-->

    <div class="notification msgsuccess" style="display: none" id="nofSuccess">
        <a class="close"></a>
        <p id="msgNofSuccess">This is a success message.</p>
    </div>
    <!-- notification msgsuccess -->

    <div class="notification msgerror" style="display: none" id="nofError">
        <a class="close"></a>
        <p id="msgNofError">This is an error message.</p>
    </div>
    <!-- notification msgerror -->


    <div class="contenttitle radiusbottom0">
        <h2 class="table"><span>Danh sách tour du lịch của sản phẩm du lịch @Model.travelProduct.Name </span></h2>
    </div>
    <!--contenttitle-->

    <table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="dyntable">
        <colgroup>
            <col class="con0" />
            <col class="con1" />
            <col class="con0" />
            <col class="con1" />
            <col class="con0" />
            <col class="con0" />
            <col class="con1" />
        </colgroup>
        <thead>
            <tr>
                <th class="head1"></th>
                <th class="head0">Ảnh</th>
                <th class="head1">Tên</th>
                <th class="head0">Giá</th>
                <th class="head1">Giới thiệu</th>
                <th class="head0">Thời gian</th>
                <th class="head1">Địa điểm</th>
                <th class="head0">Tour nổi bật</th>
                <th class="head1">Thứ tự</th>
                <th class="head0">Thao tác</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th class="head1"></th>
                <th class="head0">Ảnh</th>
                <th class="head1">Tên</th>
                <th class="head0">Giá</th>
                <th class="head1">Giới thiệu</th>
                <th class="head0">Thời gian</th>
                <th class="head1">Địa điểm</th>
                <th class="head0">Tour nổi bật</th>
                <th class="head1">Thứ tự</th>
                <th class="head0">Thao tác</th>
            </tr>
        </tfoot>
        <tbody>
            @{
                if (Model.listTravelCity != null)
                {
                    int i = 1;
                    foreach (var item in Model.listTravelCity)
                    { 
                <tr class="gradeX">
                    <td class="center">@i</td>
                    @{
                        var imageFile = "~/Content/upload/travelcity/";
                        if (item.Image != null)
                        {
                            imageFile += @item.Image;
                        }
                        else
                        {
                            imageFile += "no-photo.jpg";
                        }
                    }
                    <td class="center">
                        <img src= "@Url.Content(imageFile)" style="width:50px; height:50px" alt="" />
                    </td>
                    <td>@Html.DisplayFor(modelitem => item.Name)</td>
                    <td>@Html.DisplayFor(modelitem => item.Price)</td>
                    <td>@Truncate(item.Description, 30)</td>
                    <td>@Html.DisplayFor(modelitem => item.Time)</td>
                    <td>@Html.DisplayFor(modelitem => item.Duration)</td>
                    <td class="center">
                        <input data-id="@item.Id" style="width:15px;" class="Hot" type="checkbox" @(item.Hot == true ? "checked= checked" : "") value="true"/>
                    </td>
                    <td class="center">@Html.DisplayFor(modelitem => item.Position)</td>
                    @{
                        VietPremier.EntityAdmin user = (VietPremier.EntityAdmin)Session["User"];
                        if (user.Type == "Admin" || user.Type == "Manager")
                        {
                        <td class="center">
                           @* @Html.ActionLink("Thêm", "Insert", new { idTravelProduct = @item.IdTravelProduction })
                            &nbsp;*@
                                        @Html.ActionLink("Sửa", "Edit", new { idTravelCity = item.Id })
                            &nbsp; 
                                        <a href="#" onclick="DeleteRecord(@item.Id, @item.IdTravelProduction)">Xóa</a>
                            <br />
                        </td>
                        }
                        else
                        {
                        <td class="center">
                            @*@Html.ActionLink("Thêm", "Insert", new { idTravelProduct = @item.IdTravelProduction })
                            &nbsp;*@
                                        @Html.ActionLink("Sửa", "Edit", new { idTravelCity = item.Id })
                            <br />
                        </td>
                        }
                    }
                </tr>
                        i++;
                    }
                }
            }
        </tbody>
    </table>
</div>
<!--maincontentinner-->
